Skip to content

security: gate /api/migrate behind MIGRATION_SECRET in production#11

Open
vorcigernix wants to merge 1 commit intomainfrom
security/migrate-endpoint-auth
Open

security: gate /api/migrate behind MIGRATION_SECRET in production#11
vorcigernix wants to merge 1 commit intomainfrom
security/migrate-endpoint-auth

Conversation

@vorcigernix
Copy link
Copy Markdown
Owner

Motivation

The POST /api/migrate endpoint was completely unauthenticated — any HTTP client could trigger destructive database schema changes in production.

Changes

  • app/api/migrate/route.ts — Replace the open endpoint with Authorization: Bearer <secret> validation against a MIGRATION_SECRET env var. In production, requests without a valid token get 401. If MIGRATION_SECRET is not configured at all, the endpoint rejects everything (fail-closed). Development and test modes remain open for local curl bootstrap.
  • lib/env-validation.ts — Add MIGRATION_SECRET to the env schema (optional, min 16 chars).
  • environment.example — Document the new variable with generation instructions.
  • __tests__/api/migrate.test.ts — 9 tests covering: missing secret, missing header, wrong token, wrong auth scheme, valid secret, migration failure, migration throw, and dev/test mode bypass.

The migrate endpoint was previously unauthenticated, allowing anyone to
trigger destructive schema changes. Add Bearer-token auth via a
MIGRATION_SECRET env var in production. Development/test mode remains
open for local DB bootstrap.

Co-authored-by: Ona <no-reply@ona.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
prcat Building Building Preview, Comment Mar 2, 2026 6:15am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant